package view.campaign;

import java.awt.event.ActionListener;

import javax.swing.JPanel;
import javax.swing.SpringLayout;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import java.awt.Font;

public class NewCustomer extends JPanel
{
	private JTextField tCustName;
	private JTextField tEmail;
	private JTextField tPhone;
	private JButton btnSave;
	private JScrollPane scrollPane;
	private JTable table;
	private JButton btnMessage;
	private JButton btnEmail;
	
	public NewCustomer() 
	{
		SpringLayout springLayout = new SpringLayout();
		setLayout(springLayout);
		
		JLabel lblCustomerName = new JLabel("Customer Name");
		lblCustomerName.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, lblCustomerName, 30, SpringLayout.NORTH, this);
		springLayout.putConstraint(SpringLayout.WEST, lblCustomerName, 30, SpringLayout.WEST, this);
		add(lblCustomerName);
		
		tCustName = new JTextField();
		tCustName.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, tCustName, 6, SpringLayout.SOUTH, lblCustomerName);
		springLayout.putConstraint(SpringLayout.WEST, tCustName, 30, SpringLayout.WEST,this);
		add(tCustName);
		tCustName.setColumns(20);
		
		JLabel lblEmail = new JLabel("Email");
		lblEmail.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, lblEmail, 30, SpringLayout.NORTH,this);
		springLayout.putConstraint(SpringLayout.WEST, lblEmail, 30, SpringLayout.EAST,tCustName);
		add(lblEmail);
		
		tEmail = new JTextField();
		tEmail.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, tEmail, 0, SpringLayout.NORTH,tCustName);
		springLayout.putConstraint(SpringLayout.WEST, tEmail, 30, SpringLayout.EAST, tCustName);
		add(tEmail);
		tEmail.setColumns(20);
		
		JLabel lblPhoneno = new JLabel("Phone No");
		lblPhoneno.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, lblPhoneno, 30, SpringLayout.NORTH,this);
		springLayout.putConstraint(SpringLayout.WEST, lblPhoneno, 30, SpringLayout.EAST,tEmail);
		add(lblPhoneno);
		
		tPhone = new JTextField();
		tPhone.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH,tPhone, 0, SpringLayout.NORTH,tEmail);
		springLayout.putConstraint(SpringLayout.WEST, tPhone, 30, SpringLayout.EAST, tEmail);
		add(tPhone);
		tPhone.setColumns(20);
		
		btnSave = new JButton("Save");
		btnSave.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.WEST, btnSave, 30, SpringLayout.EAST,tPhone);
		springLayout.putConstraint(SpringLayout.NORTH, btnSave, 0, SpringLayout.NORTH,tPhone);
		add(btnSave);
		btnSave.setActionCommand("Save");
		
		JSeparator separator = new JSeparator();
		springLayout.putConstraint(SpringLayout.NORTH, separator,30, SpringLayout.SOUTH,tCustName);
		springLayout.putConstraint(SpringLayout.EAST, separator, -30, SpringLayout.EAST, this);
		springLayout.putConstraint(SpringLayout.WEST, separator, 30, SpringLayout.WEST,this);
		add(separator);
		
		btnMessage = new JButton("Send MSG");
		btnMessage.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.SOUTH, btnMessage, -30, SpringLayout.SOUTH,this);
		springLayout.putConstraint(SpringLayout.WEST, btnMessage, 30, SpringLayout.WEST,this);
		add(btnMessage);
		btnMessage.setActionCommand("Send MSG");
		
		btnEmail = new JButton("Send Email");
		btnEmail.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, btnEmail, 0, SpringLayout.NORTH, btnMessage);
		springLayout.putConstraint(SpringLayout.WEST, btnEmail, 30, SpringLayout.EAST, btnMessage);
		add(btnEmail);
		btnEmail.setActionCommand("Send Email");
		
		scrollPane = new JScrollPane();
		springLayout.putConstraint(SpringLayout.NORTH, scrollPane, 30, SpringLayout.NORTH,separator);
		springLayout.putConstraint(SpringLayout.SOUTH, scrollPane, -30, SpringLayout.NORTH,btnMessage);
		springLayout.putConstraint(SpringLayout.WEST, scrollPane, 30, SpringLayout.WEST, this);
		springLayout.putConstraint(SpringLayout.EAST, scrollPane, -30, SpringLayout.EAST, this);
		add(scrollPane);
		
		table = new JTable();
		table.setModel(new DefaultTableModel(
			new Object[][] {
			},
			new String[] {
				"Name", "Email", "Phone_no", "CheckBox"
			}
		) {
			boolean[] columnEditables = new boolean[] {
				false, false, false, true
			};
			public boolean isCellEditable(int row, int column) {
				return columnEditables[column];
			}
		});
		scrollPane.setViewportView(table);
	}
	
	public JTextField gettCustName() {
		return tCustName;
	}

	public void settCustName(JTextField tCustName) {
		this.tCustName = tCustName;
	}

	public JTextField gettEmail() {
		return tEmail;
	}

	public void settEmail(JTextField tEmail) {
		this.tEmail = tEmail;
	}

	public JTextField gettPhone() {
		return tPhone;
	}

	public void settPhone(JTextField tPhone) {
		this.tPhone = tPhone;
	}

	public JButton getBtnSave() {
		return btnSave;
	}

	public void setBtnSave(JButton btnSave) {
		this.btnSave = btnSave;
	}

	public JScrollPane getScrollPane() {
		return scrollPane;
	}

	public void setScrollPane(JScrollPane scrollPane) {
		this.scrollPane = scrollPane;
	}

	public JTable getTable() {
		return table;
	}

	public void setTable(JTable table) {
		this.table = table;
	}

	public JButton getBtnMessage() {
		return btnMessage;
	}

	public void setBtnMessage(JButton btnMessage) {
		this.btnMessage = btnMessage;
	}

	public JButton getBtnEmail() {
		return btnEmail;
	}

	public void setBtnEmail(JButton btnEmail) {
		this.btnEmail = btnEmail;
	}

	
	public void actionListener(ActionListener al)
	{
		btnSave.addActionListener(al);
		btnEmail.addActionListener(al);
		btnMessage.addActionListener(al);
	}
}
